package com.qf.controller;

import com.qf.pojo.User;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 测试 接收请求的参数
 * @author lixu
 */
@Controller
@RequestMapping("/param")
public class ParamController {

    /**
     *  接收传递参数   SpringMVC：强大
     *
     * // http://localhost:8080/param/test1?id=1&name=shine&gender=true&birth=2020/12/12 12:13:20
     *
     * @DateTimeFormat(pattern = "yyyyMMddHHmmss") Date birth : 基本类型
     */
    @RequestMapping(value = "/test1")
    public String test1(Integer id, String name, Boolean gender,Date birth){

        System.out.println("id:" + id);
        System.out.println("name:" + name);
        System.out.println("gender:" + gender);
        System.out.println("birth:" + birth);

        return "hello";
    }

    /**
     *   使用实体对象   接收参数
     *
     * // http://localhost:8080/param/test1?id=1&name=shine&gender=true&birth=2020/12/12 12:13:20
     */
    @RequestMapping(value = "/test2")
    public String test2(User user){

        System.out.println(user.toString());

        return "hello";
    }
    /**
     * 集合
     * /param/test4?users[0].id=1&users[0].name=shine&users[0].gender=true&users[1].id=2&users[1].name=zhangsan
     *
     * request.getPa
     *
     * List<User>  = new Array()
     */
    @RequestMapping(value = "/test3")
    public String test3(User user){

        for (User userUser : user.getUsers()) {
            System.out.println(userUser);
        }

        return "hello";
    }
}
